<?php
function outLog($a,$b){
    if($b==0){
        echo "[".time()." $a] success\n";
    }else{
        echo "[".time()." $a] failed\n";
        exit($b);
    }
}
function getOS(){
    $a=php_uname("s");
    if(strpos($a,"Windows")>=0){return"Windows";}
    if(strpos($a,"Linux")>=0){return"Linux";}
    return"";
}
function run($a,$b){
    exec("$a $b",$c,$d);
    outLog($a,$d);
}
if(getOS()=="Windows"){
    if(is_dir("release")){run("rd","/s /q release");}
    if(!is_dir("build")){run("md","build");}
    run("md","release");
    run("md","release\\config");
    run("xcopy","src build\\ /E /C /I");
    file_put_contents("build/index.php","");
    file_put_contents("release/index.php","<?php include(\"phar://core.phar/core/core.php\");");
    $phar = new Phar("release/core.phar",0,"index.php");
    $phar->buildFromDirectory("build");
    $phar->setDefaultStub("index.php","index.php");
    run("xcopy","config release\\config");
    run("rd","/s /q build");
    outLog("build",0);
}elseif(getOS()=="Linux"){
    echo "[".time()." failed] you can only run this script on windows.";
}